﻿<?php require_once('../Connections/hitekforyou.php'); ?>
<?php
require_once('checklogin.php');
//MX Widgets3 include
require_once('../includes/wdg/WDG.php');

error_reporting(0);
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the KT_back class
require_once('../includes/nxt/KT_back.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Make unified connection variable
$conn_hitekforyou = new KT_connection($hitekforyou, $database_hitekforyou);

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("TenCongTyQC", true, "text", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("SDT", true, "text", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("UrlBanner", true, "", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("UrlClick", true, "text", "", "", "", "Please enter a valid value.");
$formValidation->addField("TGBD", true, "date", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("TGKT", true, "date", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$tNGs->prepareValidation($formValidation);
// End trigger

//start Trigger_FileDelete trigger
//remove this line if you want to edit the code by hand 
function Trigger_FileDelete(&$tNG) {
  $deleteObj = new tNG_FileDelete($tNG);
  $deleteObj->setFolder("../UploadImage/");
  $deleteObj->setDbFieldName("UrlBanner");
  return $deleteObj->Execute();
}
//end Trigger_FileDelete trigger

//start Trigger_ImageUpload trigger
//remove this line if you want to edit the code by hand 
function Trigger_ImageUpload(&$tNG) {
  $uploadObj = new tNG_ImageUpload($tNG);
  $uploadObj->setFormFieldName("UrlBanner");
  $uploadObj->setDbFieldName("UrlBanner");
  $uploadObj->setFolder("../UploadImage/QuangCao/");
  $uploadObj->setResize("false", 185, 225);
  $uploadObj->setMaxSize(2000);
  $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png, swf");
  $uploadObj->setRename("auto");
  return $uploadObj->Execute();
}
//end Trigger_ImageUpload trigger

// Make an insert transaction instance
$ins_quangcao = new tNG_multipleInsert($conn_hitekforyou);
$tNGs->addTransaction($ins_quangcao);
// Register triggers
$ins_quangcao->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_quangcao->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_quangcao->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$ins_quangcao->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
// Add columns
$ins_quangcao->setTable("quangcao");
$ins_quangcao->addColumn("TenCongTyQC", "STRING_TYPE", "POST", "TenCongTyQC");
$ins_quangcao->addColumn("SDT", "STRING_TYPE", "POST", "SDT");
$ins_quangcao->addColumn("UrlBanner", "FILE_TYPE", "FILES", "UrlBanner");
$ins_quangcao->addColumn("UrlClick", "STRING_TYPE", "POST", "UrlClick");
$ins_quangcao->addColumn("TGBD", "DATE_TYPE", "POST", "TGBD");
$ins_quangcao->addColumn("TGKT", "DATE_TYPE", "POST", "TGKT");
$ins_quangcao->setPrimaryKey("idQuangCao", "NUMERIC_TYPE");

// Make an update transaction instance
$upd_quangcao = new tNG_multipleUpdate($conn_hitekforyou);
$tNGs->addTransaction($upd_quangcao);
// Register triggers
$upd_quangcao->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_quangcao->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_quangcao->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$upd_quangcao->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
// Add columns
$upd_quangcao->setTable("quangcao");
$upd_quangcao->addColumn("TenCongTyQC", "STRING_TYPE", "POST", "TenCongTyQC");
$upd_quangcao->addColumn("SDT", "STRING_TYPE", "POST", "SDT");
$upd_quangcao->addColumn("UrlBanner", "FILE_TYPE", "FILES", "UrlBanner");
$upd_quangcao->addColumn("UrlClick", "STRING_TYPE", "POST", "UrlClick");
$upd_quangcao->addColumn("TGBD", "DATE_TYPE", "POST", "TGBD");
$upd_quangcao->addColumn("TGKT", "DATE_TYPE", "POST", "TGKT");
$upd_quangcao->setPrimaryKey("idQuangCao", "NUMERIC_TYPE", "GET", "idQuangCao");

// Make an instance of the transaction object
$del_quangcao = new tNG_multipleDelete($conn_hitekforyou);
$tNGs->addTransaction($del_quangcao);
// Register triggers
$del_quangcao->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
$del_quangcao->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$del_quangcao->registerTrigger("AFTER", "Trigger_FileDelete", 98);
// Add columns
$del_quangcao->setTable("quangcao");
$del_quangcao->setPrimaryKey("idQuangCao", "NUMERIC_TYPE", "GET", "idQuangCao");



// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($conn_hitekforyou);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "KT_logout_now");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "login.php");
// Add columns
// End of logout transaction instance

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsquangcao = $tNGs->getRecordset("quangcao");
$row_rsquangcao = mysql_fetch_assoc($rsquangcao);
$totalRows_rsquangcao = mysql_num_rows($rsquangcao);

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wdg="http://ns.adobe.com/addt">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="quantri.css" rel="stylesheet" type="text/css" />
<script src="../AC_RunActiveContent.js" type="text/javascript"></script>

<title>Quản trị web HitekForYou</title>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<script src="../includes/nxt/scripts/form.js" type="text/javascript"></script>
<script src="../includes/nxt/scripts/form.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_FORM_SETTINGS = {
  duplicate_buttons: true,
  show_as_grid: true,
  merge_down_value: true
}
</script>
<script type="text/javascript" src="../includes/common/js/sigslot_core.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js.php"></script>
<script type="text/javascript" src="../includes/wdg/classes/Calendar.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/SmartDate.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar_stripped.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar-setup_stripped.js"></script>
<script src="../includes/resources/calendar.js"></script>
</head>

<body>

<?php include("admin_template/header.php"); ?>
<?php include("admin_template/admin_banner.php"); ?> 
<table id="main" width="990" border="1" align="center" cellpadding="0" cellspacing="0">
 <tr>
    <td width="200" align="left" valign="top" bgcolor="#66CC00" id="cottrai">
      <div align="left">
      <?php include("menu.php"); ?>  
      </div>       </td>
    <td id="cotphai" width="790" align="left" valign="top" bgcolor="#CCFF00">
   
  
   
    <?php
	echo $tNGs->getErrorMsg();
?>
    <div class="KT_tng">
      <h1>
        <?php 
// Show IF Conditional region1 
if (@$_GET['idQuangCao'] == "") {
?>
Thêm
          <?php 
// else Conditional region1
} else { ?>
    Cập nhật
          <?php } 
// endif Conditional region1
?>
        Quảng cáo </h1>
      <div class="KT_tngform">
        <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" enctype="multipart/form-data">
          <?php $cnt1 = 0; ?>
          <?php do { ?>
            <?php $cnt1++; ?>
            <?php 
// Show IF Conditional region1 
if (@$totalRows_rsquangcao > 1) {
?>
              <h2><?php echo NXT_getResource("Record_FH"); ?> <?php echo $cnt1; ?></h2>
              <?php } 
// endif Conditional region1
?>
            <table cellpadding="2" cellspacing="0" class="KT_tngtable">
              <tr>
                <td class="KT_th"><label for="TenCongTyQC_<?php echo $cnt1; ?>">Tên Công ty Quảng Cáo:</label></td>
                <td><input type="text" name="TenCongTyQC_<?php echo $cnt1; ?>" id="TenCongTyQC_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsquangcao['TenCongTyQC']); ?>" size="32" maxlength="255" />
                    <?php echo $tNGs->displayFieldHint("TenCongTyQC");?> <?php echo $tNGs->displayFieldError("quangcao", "TenCongTyQC", $cnt1); ?> </td>
              </tr>
              <tr>
                <td class="KT_th"><label for="SDT_<?php echo $cnt1; ?>">Số điện thoại:</label></td>
                <td><input type="text" name="SDT_<?php echo $cnt1; ?>" id="SDT_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsquangcao['SDT']); ?>" size="32" maxlength="20" />
                    <?php echo $tNGs->displayFieldHint("SDT");?> <?php echo $tNGs->displayFieldError("quangcao", "SDT", $cnt1); ?> </td>
              </tr>
              <tr>
                <td class="KT_th"><label for="UrlBanner_<?php echo $cnt1; ?>">Đường dẫn Banner:</label></td>
                <td><input type="file" name="UrlBanner_<?php echo $cnt1; ?>" id="UrlBanner_<?php echo $cnt1; ?>" size="32" />
                    <?php echo $tNGs->displayFieldError("quangcao", "UrlBanner", $cnt1); ?><br />
                    <?php echo $row_rsquangcao['UrlBanner']; ?></td>
              </tr>
              <tr>
                <td class="KT_th"><label for="UrlClick_<?php echo $cnt1; ?>">Đường dẫn Click:</label></td>
                <td><input type="text" name="UrlClick_<?php echo $cnt1; ?>" id="UrlClick_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsquangcao['UrlClick']); ?>" size="32" maxlength="255" />
                    <?php echo $tNGs->displayFieldHint("UrlClick");?> <?php echo $tNGs->displayFieldError("quangcao", "UrlClick", $cnt1); ?> </td>
              </tr>
              <tr>
                <td class="KT_th"><label for="TGBD_<?php echo $cnt1; ?>">Thời gian bắt đầu:</label></td>
                <td><input name="TGBD_<?php echo $cnt1; ?>" id="TGBD_<?php echo $cnt1; ?>" value="<?php echo KT_formatDate($row_rsquangcao['TGBD']); ?>" size="10" maxlength="22" wdg:mondayfirst="false" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:singleclick="false" wdg:restricttomask="no" wdg:readonly="true" />
                    <?php echo $tNGs->displayFieldHint("TGBD");?> <?php echo $tNGs->displayFieldError("quangcao", "TGBD", $cnt1); ?> </td>
              </tr>
              <tr>
                <td class="KT_th"><label for="TGKT_<?php echo $cnt1; ?>">Thời gian kết thúc:</label></td>
                <td><input name="TGKT_<?php echo $cnt1; ?>" id="TGKT_<?php echo $cnt1; ?>" value="<?php echo KT_formatDate($row_rsquangcao['TGKT']); ?>" size="10" maxlength="22" wdg:mondayfirst="false" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:singleclick="false" wdg:restricttomask="no" wdg:readonly="true" />
                    <?php echo $tNGs->displayFieldHint("TGKT");?> <?php echo $tNGs->displayFieldError("quangcao", "TGKT", $cnt1); ?> </td>
              </tr>
            </table>
            <input type="hidden" name="kt_pk_quangcao_<?php echo $cnt1; ?>" class="id_field" value="<?php echo KT_escapeAttribute($row_rsquangcao['kt_pk_quangcao']); ?>" />
            <?php } while ($row_rsquangcao = mysql_fetch_assoc($rsquangcao)); ?>
          <div class="KT_bottombuttons">
            <div>
              <?php 
      // Show IF Conditional region1
      if (@$_GET['idQuangCao'] == "") {
      ?>
                <input type="submit" name="KT_Insert1" id="KT_Insert1" value="Thêm" />
                <?php 
      // else Conditional region1
      } else { ?>
                <div class="KT_operations">
                  <input type="submit" name="KT_Insert1" value="Thêm mới" onclick="nxt_form_insertasnew(this, 'idQuangCao')" />
                </div>
                <input type="submit" name="KT_Update1" value="Cập nhật" />
                <input type="submit" name="KT_Delete1" value="Xóa" onclick="return confirm('<?php echo NXT_getResource("Bạn có chắc muốn xóa ?"); ?>');" />
                <?php }
      // endif Conditional region1
      ?>
              <input type="button" name="KT_Cancel1" value="Hủy" onclick="return UNI_navigateCancel(event, '../includes/nxt/back.php')" />
            </div>
          </div>
        </form>
      </div>
      <br class="clearfixplain" />
    </div>
    <p>&nbsp;</p>
  </tr>
</table>
<?php include("admin_template/footer.php"); ?>  
</body>
</html>

